package cn.ante.ymcc.controller;

import cn.ante.ymcc.doc.CourseDoc;
import cn.ante.ymcc.dto.CourseEsSearchDto;
import cn.ante.ymcc.result.JSONResult;
import cn.ante.ymcc.service.ICourseESService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
public class SearchController {

    @Autowired
    private ICourseESService courseESService;

    @PostMapping("/course/save")
    @PreAuthorize("hasAuthority('es:saveCourse')")
    public JSONResult saveElasticSearch(@RequestBody CourseDoc courseDoc){
        courseESService.saveElasticSearch(courseDoc);
        return JSONResult.success();
    }

    @PostMapping("/course/remove/{id}")
    public JSONResult removeElasticSearch(@PathVariable("id") Long id){
        courseESService.removeElasticSearch(id);
        return JSONResult.success();
    }

    /**
     * @Title: es高级搜索，即前端首页搜索
     * @Description:
     * @Author: Nai
     * @Version: 1.0
     * @Date:  2022/8/14 15:39
     * @Parameters:
     * @Return
     */
    @RequestMapping(value="/course/search",method= RequestMethod.POST)
    public JSONResult  search(@RequestBody CourseEsSearchDto dto){
        return JSONResult.success(courseESService.search(dto));
    }
}
